﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace Lamex.mIE.Common
{
    public class GetShowPic
    {
        public static Tuple<List<string>, List<string>> ShowPic_STD(string Product_Type,string DWG_No, string REF_PART,string Part_No)
        {
            List<string> pathList = new List<string>();//存放标准图纸
            List<string> pathList_REF = new List<string>();//存放参考图纸
            Tuple<List<string>, List<string>> tup = new Tuple<List<string>, List<string>>(pathList, pathList_REF);
            //显示图片
            XmlDocument doc = new XmlDocument();
            doc.Load(Application.StartupPath + "\\PicturePathConfig.xml");
            XmlNode xn = doc.SelectSingleNode("/Pictures/Picture");
            XmlNodeList xnl = xn.ChildNodes;
            string filename = "";//标准图纸路径     
            string filename_CK = "";//参考图纸路径   
            string filename_Temp = "";//临时图纸路径
            int Count = 0;

            foreach (XmlNode xn1 in xnl)
            {
                //XmlElement xe = (XmlElement)xn1;
                //XmlNodeList xn2 = xe.ChildNodes;
                if (DWG_No.Trim().Length > 0 && DWG_No.Substring(1, 2) == "96")
                {
                    if (Product_Type == "Panel")
                    {
                        if (xn1.Name == "panelSjPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "MCG")
                    {
                        if (xn1.Name == "MCGSjPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "Laminate")
                    {
                        if (xn1.Name == "LaminateSJPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                    else
                    {
                        if (xn1.Name == "panelSjPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                }
                else
                {
                    if (Product_Type == "Panel")
                    {
                        if (xn1.Name == "panlSdPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "MCG")
                    {
                        if (xn1.Name == "MCGSDPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "Laminate")
                    {
                        if (xn1.Name == "LaminateSDPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                    else
                    {
                        if (xn1.Name == "panlSdPath")
                            filename = xn1.InnerText;//读取标准图片路径 
                    }
                }
                //判断参考图纸
                if (REF_PART.Trim().Length > 0 && REF_PART.Substring(1, 2) == "96")
                {
                    if (Product_Type == "Panel")
                    {
                        if (xn1.Name == "panelSjPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "MCG")
                    {
                        if (xn1.Name == "MCGSjPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "Laminate")
                    {
                        if (xn1.Name == "LaminateSJPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                    else
                    {
                        if (xn1.Name == "panelSjPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                }
                else
                {
                    if (Product_Type == "Panel")
                    {
                        if (xn1.Name == "panlSdPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "MCG")
                    {
                        if (xn1.Name == "MCGSDPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                    else if (Product_Type == "Laminate")
                    {
                        if (xn1.Name == "LaminateSDPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                    else
                    {
                        if (xn1.Name == "panlSdPath")
                            filename_CK = xn1.InnerText;//读取标准图片路径 
                    }
                }
                if (xn1.Name == "Sums")
                    Count = Convert.ToInt32(xn1.InnerText);//读取张数
                if (xn1.Name == "TempPath")
                    filename_Temp = xn1.InnerText;//读取临时图片路径 
            }
            for (int i = 0; i < Count; i++)
            {
                string picTemp = "";//定义每张标准图片路径          
                if (i == 0)
                {
                    picTemp = filename + DWG_No + ".tif";//标准图片只存在一张的情况
                }
                else
                {
                    picTemp = filename + DWG_No + "-" + i + ".tif";//标准图片存在多张的情况
                }
                if (!File.Exists(picTemp))
                {
                    continue;
                }
                pathList.Add(picTemp);
            }
            for (int j = 0; j < Count; j++)
            {
                string picTemp_REF = "";//定义每张参考图片路径
                if (j == 0)
                {
                    picTemp_REF = filename_CK + REF_PART + ".tif";//参考图片只存在一张的情况
                }
                else
                {
                    picTemp_REF = filename_CK + REF_PART + "-" + j + ".tif";//参考图片存在多张的情况
                }
                if (!File.Exists(picTemp_REF))
                {
                    continue;
                }
                pathList_REF.Add(picTemp_REF);
            }
            //增加临时图纸判断
            if (pathList.Count <= 0)
            {
                string strTemp = filename_Temp + DWG_No + ".tif";
                if (File.Exists(strTemp))
                    pathList.Add(strTemp);
            }
            if (pathList_REF.Count <= 0)
            {
                string strTemp = filename_Temp + REF_PART + ".tif";
                if (File.Exists(strTemp))
                    pathList_REF.Add(strTemp);
            }

            return tup;
        }

    }
}
